<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:uc="http://www.quickzip.org/UserControls"
    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Converters.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!--<Style x:Key="TreeViewItemFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle HorizontalAlignment="Stretch" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>-->
    <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
    <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Width" Value="16"/>
        <Setter Property="Height" Value="16"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Width="16" Height="16" Background="Transparent" Padding="5,5,5,5">
                        <Path x:Name="ExpandPath" Fill="Transparent" Stroke="#FF989898" Data="{StaticResource TreeArrow}">
                            <Path.RenderTransform>
                                <RotateTransform Angle="135" CenterX="3" CenterY="3"/>
                            </Path.RenderTransform>
                        </Path>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF1BBBFA"/>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="Transparent"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="RenderTransform" TargetName="ExpandPath">
                                <Setter.Value>
                                    <RotateTransform Angle="180" CenterX="3" CenterY="3"/>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="#FF595959"/>
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="#FF262626"/>
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="W7TreeViewItemStyle" TargetType="{x:Type TreeViewItem}">
        <Setter Property="Background" Value="Transparent"/>
        <!--<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>-->
        <Setter Property="Padding" Value="1,0,0,0"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <!--<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid HorizontalAlignment="Stretch" x:Name="baseGrid" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="19" Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Border x:Name="BdGridBorder"
                            Padding="{TemplateBinding Padding}" Grid.Column="0" Grid.ColumnSpan="3">
                            <Grid x:Name="BdGrid" >
                                <Grid.RowDefinitions>
                                    <RowDefinition MaxHeight="11"/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{StaticResource SelectedBackgroundBrush}"  Grid.RowSpan="2"
                                        Visibility="Collapsed" BorderThickness="0,1" BorderBrush="#FFCCF0FF" />

                                <Rectangle x:Name="BdUpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed" />


                                <Border x:Name="Bd2" SnapsToDevicePixels="true" Background="{StaticResource SelectedBackgroundBrush}" Grid.RowSpan="2" 
                                        Visibility="Collapsed" BorderThickness="0,1" BorderBrush="#FFCCF0FF" >
                                    <Border.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform ScaleX="-2" />
                                        </TransformGroup>
                                    </Border.RenderTransform>
                                </Border>
                                <Rectangle x:Name="Bd2UpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed" >
                                    <Rectangle.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform ScaleX="-2" />
                                        </TransformGroup>
                                    </Rectangle.RenderTransform>
                                </Rectangle>
                            </Grid>
                        </Border>


                        <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" 
                                      IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                                      Opacity="{Binding Path=(uc:W7TreeViewItemUtils.ArrowOpacity), 
                                      RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}}"
                                      />
                        <ContentPresenter x:Name="PART_Header" HorizontalAlignment="Stretch"  Grid.Column="1"  Grid.ColumnSpan="2"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" Margin="{TemplateBinding BorderThickness}"/>
                        <ItemsPresenter x:Name="ItemsHost" Margin="8,0,0,0" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" />
                        <!--<ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/>-->
                    </Grid>
                    <ControlTemplate.Triggers>


                        <DataTrigger Value="True" Binding="{Binding Path=(uc:W7TreeViewItemUtils.IsDragOver), 
                                RelativeSource={RelativeSource AncestorType={x:Type TreeView}}, Mode=OneWay}">
                            <Setter TargetName="PART_Header" Property="HorizontalAlignment" Value="Left" />
                        </DataTrigger>

                        <Trigger Property="IsExpanded" Value="false">
                            <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <!--<Setter Property="Background" TargetName="Bd" Value="{StaticResource SelectedBackgroundBrush}"/>
                            <Setter Property="Background" TargetName="Bd2" Value="{StaticResource SelectedBackgroundBrush}"/>
                            <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource SolidBorderBrush}"/>
                            <Setter Property="BorderBrush" TargetName="Bd2" Value="{StaticResource SolidBorderBrush}"/>-->
                            <Setter Property="Visibility" TargetName="BdUpperHighlight" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="Bd2UpperHighlight" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="Bd" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="Bd2" Value="Visible"/>
                            <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>-->
                        </Trigger>
                        <Trigger SourceName="PART_Header" Property="IsMouseOver" Value="true">
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource HotTrackBrush}"/>
                            <Setter Property="Background" TargetName="Bd2" Value="{StaticResource HotTrackBrush}"/>
                            <Setter Property="Visibility" TargetName="BdUpperHighlight" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="Bd2UpperHighlight" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="Bd" Value="Visible"/>
                            <Setter Property="Visibility" TargetName="Bd2" Value="Visible"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="true"/>
                                <Condition Property="IsSelectionActive" Value="false"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource InactiveSelectedBackgroundBrush}"/>
                            <Setter Property="Background" TargetName="Bd2" Value="{StaticResource InactiveSelectedBackgroundBrush}"/>
                            <Setter Property="BorderBrush" TargetName="Bd" Value="#FFCFCFCF"/>
                            <Setter Property="BorderBrush" TargetName="Bd2" Value="#FFCFCFCF"/>
                            <!--<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>-->
                        </MultiTrigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>

                        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                            <BeginStoryboard>
                                <Storyboard Storyboard.Target="{Binding}">
                                    <DoubleAnimation 
                                        Storyboard.TargetProperty="Opacity" From="0.5" To="1" 
                                        Duration="0:0:1" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>

            <!--This trigger is needed, because RelativeSource binding can only succeeds if the current MenuItem is already connected to its visual parent-->
            <Trigger Property="IsVisible" Value="True">
                <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
                <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            </Trigger>

            <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel HorizontalAlignment="Stretch"/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>


</ResourceDictionary>
